package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Dish;
import com.example.mapper.DishMapper;
import com.example.service.DishService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {
    
    @Override
    public List<Dish> listAll() {
        LambdaQueryWrapper<Dish> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Dish::getCreateTime);
        return this.list(wrapper);
    }
    
    @Override
    public Dish getById(Long id) {
        return super.getById(id);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveDish(Dish dish) {
        return this.save(dish);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateDish(Dish dish) {
        return this.updateById(dish);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteDish(Long id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateStatus(Long id, Integer status) {
        Dish dish = getById(id);
        if (dish == null) {
            return false;
        }
        dish.setStatus(status);
        return updateById(dish);
    }
} 